package com.bstek.demo.urule.cluster.mq.redis.service;

import com.bstek.demo.urule.cluster.mq.CustomKnowledgeCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(CustomKnowledgeCacheService.BEAN_ID)
public class RedisKnowledgeCacheServiceImpl implements CustomKnowledgeCacheService {

    Logger log= LoggerFactory.getLogger(RedisKnowledgeCacheServiceImpl.class);

    @Resource
    RedisTemplate redisTemplate;

    @Value("${urule.ext.packetcache.prefix:packetcache:packetcache_}")
    String packetCachePrefix;

    @Value("${urule.ext.packetcache.suffix:_timestamp}")
    String timestampSuffix;

    @Value("${urule.knowledgePackageFileStorePath}")
    String knowledgePackageFileStorePath;

    @Override
    public String getCache(long packetId) {
        String key= packetCachePrefix + packetId;
        log.info("redis-key={}",key);
        return (String) redisTemplate.opsForValue().get(key);
    }

    @Override
    public String getKnowledgePackageFileStorePath() {
        return knowledgePackageFileStorePath;
    }


}
